#define _CRT_SECURE_NO_WARNINGS
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
class SV
{
private:
	char *ten, *lop;
public:
	SV(char *t, char *l)
	{
		ten = new char[strlen(t) + 1];
		strcpy(ten, t);
		lop = new char[strlen(l) + 1];
		strcpy(lop, l);
	}
	~SV()
	{
		delete ten;
		delete lop;
	}
	void display()
	{
		cout << "\n\n Ten: " << ten;
		cout << "\t Lop: " << lop;
	}
};
class SVTC : public SV
{
private:
	int hocphi;
public:
	SVTC(char *t, char *l, int hp = 0) :SV(t, l)
	{
		hocphi = hp;
	}
	void display()
	{
		SV::display();
		cout << "\t Hoc phi: " << hocphi;
	}
};

class SVCQ :public SVTC
{
private:
	int diemtb, hocbong;
public:

	SVCQ(char *t, char *l, int hp, int dtb, int hb) :SVTC(t, l, hp)
	{
		diemtb = dtb;
		hocbong = hb;
	}
	void display()
	{
		SVTC::display();
		cout << "\t Diem TB: " << diemtb;
		cout << "\t Hoc bong: " << hocbong;
	}
	int operator>(SVCQ &d)
	{
		if (diemtb>d.diemtb)
			return 1;
		return 0;
	}
};
void main()
{
	int i, j, n = 3;
	char t[10], l[10];
	int hp, hb, dtb;
	SVCQ *a[3], *tg;
	for (i = 0; i<n; i++)
	{
		cout << "\n Nhap sv thu " << i + 1 << " ";
		cout << "\n Nhap Ten: "; gets(t);
		cout << "\n Nhap Lop: "; gets(l);
		cout << "\n Nhap hoc Phi: "; cin >> hp;
		cout << "\n Nhap Diem TB: "; cin >> dtb;
		cout << "\n Nhap hoc Bong: "; cin >> hb;
		a[i] = new SVCQ(t, l, hp, dtb, hb);
	}
	cout << "\n\n Thong tin sv truoc khi sap xep: ";
	for (i = 0; i<n; i++)
		a[i]->display();
	for (i = 0; i<n - 1; i++)
		for (j = i + 1; j<n; j++)
			if (*a[j]>*a[i])
			{
		tg = a[i];
		a[i] = a[j];
		a[j] = tg;
			}
	cout << "\n --------------------";
	cout << "\n\n Thong tin sap xep giam dan theo Diem TB: ";
	for (i = 0; i<n; i++)
		a[i]->display();
	_getch();
}
